package com.kaigejava.juc.atomicdemo;

import com.sun.org.apache.regexp.internal.RE;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author kaigejava
 * java.util.concurrent.atomic包demo
 */
public class AtomicDemo implements  Runnable{
   /**private volatile int   shardData = 0;**/
    private AtomicInteger shardData = new AtomicInteger(0);
    @Override
    public void run() {
        try {
            Thread.sleep(200);
            System.out.println(Thread.currentThread().getName()+":"+getShardData());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    public  int getShardData(){
        //return  shardData++;
       return shardData.getAndIncrement();
    }
}


